package controller;

import java.io.IOException;

import dao.XxDao;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class addUserServlet
 */
@WebServlet("/XxStudentAddServlet")
public class XxStudentAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String id = request.getParameter("id");
        String name = request.getParameter("name");
        String classid = request.getParameter("class");
        String roomid = request.getParameter("roomid");
        String password = request.getParameter("password");
//     测试
        System.out.println("AddWeiGuiServlet id:"+id+"  time:"+name+"  type:"+classid+" because:"+roomid+"roomid"+password);

        
        XxDao dao = new XxDao();
        boolean tip = dao.addStudentXx(id, name,password, classid, roomid);
    	

        // 如果添加用户成功，转发到userlList.jsp，列出所有用户
        if (tip) {
            // 验证成功，转发到 welcome.jsp
        	response.sendRedirect("View_xx/XxStudent.jsp");
            
        } else {
            // 验证失败，重新回到 login.jsp
        	 response.getWriter().write("UPDATEFAILE");
        }
	}
}

